<!-- frontend/src/views/goods/components/Reviews.vue -->
<script setup>
import { ref, onMounted } from 'vue'
import { getGoodsReviews } from '@/api/goods'

const props = defineProps({
  goodsId: {
    type: [String, Number],
    required: true
  }
})

const reviews = ref([])

const loadReviews = async () => {
  try {
    const res = await getGoodsReviews(props.goodsId)
    reviews.value = res.results || []
  } catch (error) {
    console.error('获取评价失败:', error)
  }
}
// onMounted的作用是：在组件挂载时执行一次，用于初始化数据
onMounted(() => {
  loadReviews()
})
</script>
<template>
  <div class="reviews">
    <h3>用户评价</h3>

    <div v-if="reviews.length === 0" class="no-reviews">
      <el-empty description="暂无评价，快来抢沙发吧！" />
    </div>

    <div v-else>
      <div v-for="review in reviews" :key="review.id" class="review-item">
        <div class="review-content">{{ review.content }}</div>
      </div>
    </div>
  </div>
</template>

